//
//  ContactTableViewCell.m
//  通讯录
//
//  Created by dllo on 16/6/21.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ContactTableViewCell.h"
#import "Contact.h"

#define kWith self.contentView.frame.size.width
#define kHeight self.contentView.frame.size.height

@interface ContactTableViewCell()

@property (nonatomic, retain) UIImageView *headerImageView;

@property (nonatomic, retain) UILabel *nameLabel;

@property (nonatomic, retain) UILabel *numberLabel;


@end

@implementation ContactTableViewCell

-(void)dealloc
{
    [_headerImageView release];
    [_nameLabel release];
    [_numberLabel release];
    
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor colorWithRed:0.99 green:0.92 blue:0.94 alpha:1.0];
        
        self.headerImageView = [[UIImageView alloc]init];
        [self.contentView addSubview:self.headerImageView];
        [self.headerImageView release];
        
        self.nameLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.nameLabel];
        [self.nameLabel release];
        
        self.numberLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.numberLabel];
        [self.numberLabel release];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.headerImageView.frame = CGRectMake(10, 10, kWith * 0.3, kHeight - 20);
    
    self.nameLabel.frame = CGRectMake(_headerImageView.frame.size.width + 40, 20, kWith * 0.5, kHeight * 0.2);
    
    self.numberLabel.frame = CGRectMake(_nameLabel.frame.origin.x, kHeight * 0.2 + 40, kWith * 0.5, kHeight * 0.2);
}

-(void)setContact:(Contact *)contact
{
    if (_contact != contact) {
        [_contact release];
        _contact = [contact retain];
    }
    
    self.imageView.image = [UIImage imageNamed:contact.header];
    
    self.nameLabel.text = contact.name;
    self.numberLabel.text = contact.number;
    
}

@end















